<template>
	<view>
		<view class="edgeInsetTop"></view>
		<view class="cu-list menu sm-border">
			<view class="cu-item arrow"
				@tap="$wanlshop.auth(`/pages/user/auth/validcode?event=resetpwd&mobile=${user.mobile}`)">
				<view class="content">
					<text>修改登录密码</text>
				</view>
			</view>
			<!-- <view class="cu-item arrow" @tap="noMobile">
				<view class="content">
					<text>修改手机号码</text>
				</view>
			</view> -->
		</view>

		<view class="cu-list menu sm-border">
			<view v-if="has_pay_password" class="cu-item arrow" @tap="setPayPwd()">
				<view class="content">
					<text>设置支付密码</text>
				</view>
			</view>
			
			<view v-if="!has_pay_password" class="cu-item arrow" @tap="$wanlshop.auth(`/pages/user/auth/resetpaypwd?mobile=${user.mobile}`)">
				<view class="content">
					<text>修改支付密码</text>
				</view>
			</view>
			
			<view v-if="!has_pay_password" class="cu-item arrow" @tap="forgetPayPwd()">
				<view class="content">
					<text>忘记支付密码</text>
				</view>
			</view>
		</view>

		<view class="cu-list menu sm-border" @tap="noUser">
			<view class="cu-item arrow">
				<view class="content">
					<text>注销账户</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				has_pay_password: this.$store.state.user.has_pay_password??false
			}
		},
		computed: {
			...mapState(['user'])
		},
		methods: {
			forgetPayPwd: function() {
				this.$wanlshop.to(
					`/pages/user/auth/validcode?event=forgetpaypwd&mobile=${this.$store.state.user.mobile}`)
			},
			setPayPwd: function() {
				this.$wanlshop.to(`/pages/user/auth/setpaypwd?mobile=${this.$store.state.user.mobile}`)
			},
			noPay() {
				this.$wanlshop.msg('暂无支付密码')
			},
			noUser() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '温馨提示:您确定要注销账号吗？注销后将无法再次注册!',
					success: function (res) {
						if (res.confirm) {
							uni.request({
								url:"/wanlshop/user/deleteAccount",
								method:'POST',
								success(res) {
									if(res.res.code == 1) {
										that.$wanlshop.msg(res.res.msg);
										setTimeout(function(){
											that.$wanlshop.back(2);
										},2000)
									} else {
										that.$wanlshop.msg(res.res.msg)
									}
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			noMobile() {
				this.$wanlshop.msg('暂不支持修改手机号码')
			}
		}
	}
</script>

<style>

</style>